package com.hui.controller;

import com.github.pagehelper.PageInfo;
import com.hui.entity.Resource;
import com.hui.entity.ResourceVo;
import com.hui.entity.ResponseResult;
import com.hui.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 李昭辉
 * @Date: 2021/08/08/15:43
 * @Description:
 */
@RestController
@RequestMapping("/resource")
public class ResourceController {
    @Autowired
    private ResourceService resourceService;

    // 资源信息分页&条件查询
    @RequestMapping("/findAllResource")
    public ResponseResult findAllResource(@RequestBody ResourceVo resourceVo) {
        PageInfo<Resource> list = resourceService.getResourceByCondition(resourceVo);
        return new ResponseResult(true, 200, "查询成功", list);
    }

    // 添加&修改资源
    @RequestMapping("/saveOrUpdateResource")
    public ResponseResult saveOrUpdateResource(@RequestBody Resource resource) {
        if (resource.getId() == null) {
            resourceService.saveResource(resource);
            return new ResponseResult(true, 200, "添加成功", null);
        } else {
            resourceService.updateResource(resource);
            return new ResponseResult(true, 200, "修改成功", null);
        }
    }

    // 删除
    @RequestMapping("/deleteResource")
    public ResponseResult deleteResource(Integer id) {
        resourceService.deleteResource(id);
        return new ResponseResult(true, 200, "删除成功", null);
    }


}
